﻿@{
    Layout = "~/_SiteLayout.cshtml";
    Validation.RequireField("Name");
    if(IsPost && Validation.IsValid())
    {
        string name = Request.Form["Name"];
        string note = Request.Form["Note"];
        using (System.Transactions.TransactionScope trans = new System.Transactions.TransactionScope())
        {
            Data.Model.Role role = new Data.Model.Role();
            role.ID = Guid.NewGuid();
            role.Name = name.Trim();
            if (!note.IsNullOrEmpty()) 
            {
                role.Note = note.Trim();
            }
            new Business.Platform.Role().Add(role);
            
            //添加一个根应用
            Data.Model.RoleApp roleApp = new Data.Model.RoleApp();
            roleApp.ID = Guid.NewGuid();
            roleApp.ParentID = Guid.Empty;
            roleApp.RoleID = role.ID;
            roleApp.Sort = 1;
            roleApp.Title = "管理目录";
            new Business.Platform.RoleApp().Add(roleApp);
            trans.Complete();
            
            <script type="text/javascript">
                alert('添加成功!');
                parent.frames[0].location = parent.frames[0].location;
                window.location = 'AddRole' + Request.Url.Query + "';";
            </script>
        }
    }
    }
<form action="" method="post" onsubmit="return new RoadUI.Validate().validateForm(this);">
<br />
<table cellpadding="0" cellspacing="1" border="0" width="99%" class="formtable">
    <tr>
        <th style="width:80px;">角色名称：</th>
        <td><input type="text" id="Name" name="Name" class="mytext" validate="empty" style="width:75%" /></td>
    </tr>
    <tr>
        <th style="width:80px;">备注说明：</th>
        <td><textarea class="mytext" id="Note" name="Note" cols="1" rows="1" style="width:95%; height:50px;" ></textarea></td>
    </tr>
</table>
<div class="buttondiv">
    <input type="submit" value="确认保存" class="mybutton" />
</div>
</form>